Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up shape transitions #6751

Merged
merged 1 commit into from Nov 21, 2022
Merged

Conversation

peterzhu2118
Copy link
Member

This commit significantly speeds up shape transitions as it changes get_next_shape_internal to not perform a lookup (and instead require the caller to perform the lookup). This avoids double lookups during shape transitions.

There is a significant (~2x) speedup in the following micro-benchmark:

puts(Benchmark.measure do
  o = Object.new

  100_000.times do |i|
    o.instance_variable_set(:"@a#{i}", 0)
  end
end)

Before:

22.393194   0.201639  22.594833 ( 22.684237)

After:

11.323086   0.022284  11.345370 ( 11.389346)

shape.c Outdated Show resolved Hide resolved
This commit significantly speeds up shape transitions as it changes
get_next_shape_internal to not perform a lookup (and instead require
the caller to perform the lookup). This avoids double lookups during
shape transitions.

There is a significant (~2x) speedup in the following micro-benchmark:

    puts(Benchmark.measure do
      o = Object.new

      100_000.times do |i|
        o.instance_variable_set(:"@A#{i}", 0)
      end
    end)

Before:

    22.393194   0.201639  22.594833 ( 22.684237)

After:

    11.323086   0.022284  11.345370 ( 11.389346)
Copy link
Contributor

@jemmaissroff jemmaissroff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Thanks for the speedup!

@peterzhu2118 peterzhu2118 merged commit 1f0888a into ruby:master Nov 21, 2022
@peterzhu2118 peterzhu2118 deleted the pz-opt-next-shape branch November 21, 2022 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants